<template>
  <MenuPage 
      :columns="courseCol"
      :data="courseData"
      :total="totalCount"
      :page.sync="curPage"
      :size.sync="curSize"
      :loading="courseListLoading"
      @queryFun="getAllCourse">
    <template slot="search">

<!--        <Divider type="vertical" />-->
        <Checkbox v-model="createByMe" @on-change="searchCou">由我创建</Checkbox>



      <!--          :current="labelExp"-->
      <!--          :data="expClassifyTag"-->
      <!--          @on-change="changeLabelExp"-->
<!--      {{expClassifyTag}}&#45;&#45;-->
        <Select filterable
          clearable
          placeholder="标签"
          v-model="labelExp"
          style="width: 150px;margin-left: 15px;"
          @on-change="changeLabelExp"
        >
          <i-option :value="item.key" v-for="(item,index) in expClassifyTag" :key="index">{{item.value}}</i-option>
        </Select>

      
      
      <Select filterable
          clearable
          placeholder="可见范围"
          v-model="isPublic"
          style="width: 150px;margin-left: 15px;"
          @on-change="changeIsPublic"
      >
        <i-option :value="item.key" v-for="(item,idx)  in visibilityArr" :key="item.key">{{item.value}}</i-option>
      </Select>
        <Input
          v-model.trim="searchCourse"
          clearable
          placeholder="课程名称"
          @on-change="searchCou"
        />
        <Button type="primary" ghost @click="showAddAndUpdate($event, 'add')" class="md-add-jh"
        ><i class="el-icon-edit"/>创建</Button>
        <Button class="header-btn" type="primary" ghost @click="refreshIcon()"
          ><i class="el-icon-refresh-right"
        /></Button>
    </template>
    <template slot="content">
      <div class="filter-wrap">
        <tag-select
          title="难 度"
          :current="selectDifficult"
          :data="diffArr"
          @on-change="changeDiff"
        ></tag-select>
        <Divider style="margin:15px 0px" />
        <tag-select
          title="方 向"
          :current="searchTypeCodeLevel1"
          ref="directionType"
          :data="directionsLevel1"
          @on-change="changeTypeLevel1"
          @height-change="updateTableHei"
       
        ></tag-select>
        <Divider style="margin:15px 0px"/>
        <tag-select
          title="类 型"
          :current="searchTypeCode"
          ref="directionType"
          :data="directionsLevel2"
          @on-change="changeType"
          @height-change="updateTableHei"
    
        ></tag-select>
        <Divider style="margin:15px 0px"/>
<!--        <tag-select-->
<!--          title="可见范围"-->
<!--          :current="isPublic"-->
<!--          :data="visibilityArr"-->
<!--          @on-change="changeIsPublic"-->
<!--        ></tag-select>-->
<!--        <Divider style="margin:15px 0px" />-->
<!--        <tag-select-->
<!--          title="标 签"-->
<!--          :current="labelExp"-->
<!--          :data="expClassifyTag"-->
<!--          @on-change="changeLabelExp"-->
<!--        ></tag-select>-->
<!--        <Divider style="margin:15px 0px" />-->
      </div>
    </template>
    <Modal v-model="expModal" title="课件列表" width="1200px" footer-hide :mask-closable="false">
      <TableList :columns="expCol1" :data="courseExpList"></TableList>
    </Modal>
    <Modal
      v-model="subscriberModal"
      :title="'使用者列表(' + curCourseName + ')'"
      footer-hide
      :mask-closable="false"
    >
      <TableList :columns="subscriberCol" :data="courseSubscriber" :height="400"></TableList>
    </Modal>
  </MenuPage>
</template>
<script>
import {
  getcourselist,
  delCourse,
  getExpList,
  courseDetail,
  courseExpDetail,
  getCourseSubscriber,
  changeCourseEnable,
  getScoreAvg
} from '@/api/selfStudy/courseExp.js';
import encryption from '@/libs/encryption.js';
import { experType, getSelLabelType } from '@/api/dict.js';
import { debounce } from '@/libs/utils';
import TagSelect from '@/components/tagSelect/tagSelect';
import pageTitle from '@/mixin/pageTitle';
export default {
  name: 'courseResource',
  mixins: [pageTitle],
  components: {
    TagSelect
  },
  data() {
    let userInfo = sessionStorage.getItem('November');
    userInfo = JSON.parse(encryption.SelfUseDecrypt(userInfo));
    //let userInfo = this.$store.state.user.userInfoGlobal;
    return {
      isSelf: '',
      USER_ID: userInfo.userId,
      USER_Name: userInfo.nickname,
      isRootDesigner: userInfo.isRootDesigner,
      totalCount: 0,
      curPage: 1,
      curSize: 10,
      ccid: '',
      courseData: [],
      //方向和类型
      directions: [],
      directionsLevel1: [],
      directionsLevel2: [],
      //搜索
      searchCourse: '',
      searchTypeCode: 'All',
      searchTypeCodeLevel1: 'All',
      searchMyCourse: '',
      selectDifficult: 'All',
      labelExp: 'All',
      diffArr: [
        {
          key: 'Simple',
          value: '简单'
        },
        {
          key: 'Medium',
          value: '中等'
        },
        {
          key: 'Hard',
          value: '较难'
        }
      ],
      isPublic: 'All',
      visibilityArr: [
        {
          key: '0',
          value: '个人'
        },
        {
          key: '1',
          value: '单位'
        },
        {
          key: '2',
          value: '系统'
        }
      ],
      createByMe: false,
      courseListLoading:false,
      //当前课程名
      curCourseName: '',
      // 课程table
      courseCol: [
        //				    {
        //						type: 'index',
        //						width: 60,
        //						align: 'center',
        //						ellipsis: true
        //					},
        {
          title: '名称',
          key: 'ccname',
          align: 'center',
          ellipsis: true,
          placement: 'top-left',
          render: (h, params) => {
            return h(
              'a',
              {
                on: {
                  click: () => {
                    this.goCourseDetail(params.row);
                  }
                }
              },
              params.row.ccname
            );
          }
        },
        {
          title: '是否自学',
          key: 'selfType',
          align: 'center',
          width: 50,
          render: (h, params) => {
            let _this = this;
            return h(
              'span',
              {
                style: {
                  color: params.row.selfType === 1 ? 'var(--status-yes)' : 'var(--status-no)'
                }
              },
              params.row.selfType === 1 ? '是' : '否'
            );
          }
        },
        {
          title: '难度',
          key: 'difficulty',
          align: 'center',
          width: 50,
          render: (h, params) => {
            let _this = this;
            return h('span', _this.handleDiffcult(params.row.difficulty));
          }
        },
        {
          title: '课时',
          key: 'hours',
          align: 'center',
          tooltip: true,
          width: 50
        },
        {
						title: '评分',
						key: 'scoreAvg',
						align: 'center',
						width: 50
        },
        {
          title: '可见范围',
          key: 'isPublic',
          align: 'center',
          width: 50,
          render: (h, params) => {
            let text = '';
            let color = '';
            if (params.row.isPublic === 1 || params.row.isPublic === '1') {
              text = '单位';
              color = 'green';
            } else if (params.row.isPublic === 0 || params.row.isPublic === '0') {
              text = '个人';
              color = '#f02828';
            } else if (params.row.isPublic === 2 || params.row.isPublic === '2') {
              text = '系统';
              color = '#2f70ff';
            }
            return h(
              'span',
              {
                style: {
                  color: color
                }
              },
              text
            );
          }
        },
        // 					{
        // 						title: '类型',
        // 						key: 'typeCode',
        // 						align: 'center',
        // //						tooltip: true,
        // 						width: 150,
        // 						render: (h, params) => {
        // 							return h('Tag', {
        // 								props: {
        // 									color: 'green'
        // 								}
        // 							}, this.handleTypeCode(params.row.typeCode))
        // 						}
        // 					},
        {
          title: '标签',
          key: 'labels',
          align: 'center',
          width: 150,
          filter:(labels) => {
            return labels ? labels.replaceAll(';', ',') : '-';
          },
          tooltip:true
        },
        {
          title: '课件个数',
          key: 'expriments',
          align: 'center',
          placement: 'top-right',
          order: 1,
          render: (h, params) => {
            //							let users = Object.values(params.row.usersMap).flat().map(user => user.userName);
            return h(
              'Tag',
              {
                props: {
                  type: 'border',
                  color: 'var(--url-color)'
                },
                style: {
                  cursor: 'pointer!important'
                },
                nativeOn: {
                  click: () => {
                    this.showCourseExpModal(params.row.ccid);
                  }
                }
              },
              params.row.expriments.length
            );
            //							let expers = params.row.expriments.map(exper => exper.ecname).join(',')
            //							return h('Poptip', {
            //								props: {
            //									placement: 'top',
            //									transfer: true,
            //									maxWidth:200
            //								},
            //								style: {
            ////
            //								}
            //							}, [
            //							    h('Tag',{props:{color:'#2f70ff'}},params.row.expriments.length),
            //								h('span', {
            //									slot: 'content',
            //									style: {
            //										whiteSpace: 'normal',
            //										wordBreak:'break-all'
            //									}
            //								}, expers)
            //							])
          }
        },
        {
          title: '使用次数',
          key: 'subscriber',
          align: 'center',
          placement: 'top-right',
          render: (h, params) => {
            return h(
              'Tag',
              {
                props: {
                  type: 'border',
                  color: 'var(--url-color)'
                },
                style: {
                  cursor: 'pointer!important'
                },
                nativeOn: {
                  click: () => {
                    if (params.row.subscriber.length > 0) {
                      this.subscriberModal = true;
                      this.curCourseName = params.row.ccname;
                      this.courseSubscriber = params.row.subscriber;
                    } else {
                      this.$Message.info('当前无人使用');
                    }
                  }
                }
              },
              params.row.subscriberNum
            );
          }
        },
        {
          title: '描述',
          key: 'description',
          align: 'center',
          width: 150,
          tooltip:true
        },
        {
          title: '设计者',
          key: 'designer',
          align: 'center',
          tooltip: true,
          width: 100
        },
        {
          title: '创建时间',
          key: 'createTime',
          align: 'center',
          tooltip: true
        },
        {
          title: '操作',
          key: 'action',
          width: 160,
          placement: 'top-right',
          opList: [
              {
                  txt: '启用',
                  show: (data) => {
                      return data.enable !== 1;
                  },
                  on: {
                    click: (data,e) => {
                      this.changeCourseEnable(data.ccid, 1);
                    }
                  },
                  disabled: (data) => {
                      return (
                          this.setReBtnStatus(data) ||
                          (data.subscriber &&
                              data.subscriber.length > 0 &&
                              data.enable === 1)
                      );
                  }
              },
              {
                  txt: '禁用',
                  show: (data) => {
                      return data.enable === 1;
                  },
                  on: {
                    click: (data,e) => {
                      this.changeCourseEnable(data.ccid, 0);
                    }
                  },
                  disabled: (data) => {
                      return (
                          this.setReBtnStatus(data) ||
                          (data.subscriber &&
                              data.subscriber.length > 0 &&
                              data.enable === 1)
                      );
                  }
              },
              // {
              //     txt: '设为自学',
              //     tooltip: true,
              //     title: '设为自学后，课程下所有的课件都会变为自学，确定设置？',
              //     show: (data) => {
              //         return data.selfType === 0;
              //     },
              //     disabled: this.setReBtnStatus,
              //     fun: this.setSelfType
              // },
              // {
              //     txt: '设为非自学',
              //     tooltip: true,
              //     title: '设为非自学后，课程下所有的课件都会变为非自学，确定设置？',
              //     show: (data) => {
              //         return data.selfType === 1;
              //     },
              //     disabled: this.setReBtnStatus,
              //     fun: this.setSelfType
              // },
              {
                  txt: '修改',
                  on: {
                    click: (data,e) => {
                      this.showAddAndUpdate({row:data}, 'modify');
                    }
                  },
                  disabled: this.setReBtnStatus
              },
              {
                  txt: '删除',
                  tooltip: true,
                  type: 'delete',
                  title: '确定要删除这个课程吗？',
                  on: {
                    'click': (data,e) => {
                      this.delCourseInfo(data.ccid);
                    }
                  },
                  disabled: this.setReBtnStatus
              }
          ]
        },
        {
          title: '操作',
          key: 'os',
          width: 160,
          align: 'left',
          ellipsis: true,
          placement: 'top-right',
          order: 2,
          action: true,
          show:false,
          render: (h, params) => {
            return h('div', [
              h(
                'i-switch',
                {
                  props: {
                    value: params.row.enable == 1,
                    size: 'large',
                    disabled:
                      this.setReBtnStatus(params.row) ||
                      (params.row.subscriber &&
                        params.row.subscriber.length > 0 &&
                        params.row.enable === 1)
                  },
                  class: {
                    switchSmall: true
                  },
                  style: {
                    width: '54px',
                    marginRight: '10px'
                  },
                  on: {
                    'on-change': () => {
                      if (params.row.enable == 1) {
                        this.changeCourseEnable(params.row.ccid, 0);
                      } else {
                        this.changeCourseEnable(params.row.ccid, 1);
                      }
                    }
                  }
                },
                [
                  h(
                    'span',
                    {
                      slot: 'open'
                    },
                    '启用'
                  ),
                  h(
                    'span',
                    {
                      slot: 'close'
                    },
                    '禁用'
                  )
                ]
              ),
              h(
                'Button',
                {
                  props: {
                    type: 'text',
                    size: 'small',
                    disabled: this.setReBtnStatus(params.row)
                  },
                  attrs: {
                    title: '修改'
                  },
                  style: {
                    background: 'none',
                    border: 'none',
                    boxShadow: 'none'
                  },
                  on: {
                    click: () => {
                      this.showAddAndUpdate(params, 'modify');
                    }
                  }
                },
                [
                  h('img', {
                    attrs: {
                      src: !this.setReBtnStatus(params.row)
                        ? require('../../../assets/project/modifys-h.png')
                        : require('../../../assets/project/modifys.png')
                    },
                    style: {
                      cursor: 'pointer',
                      'margin-right': '5px',
                      'vertical-align': 'middle',
                      display: 'inline-block',
                      marginBottom: '4px'
                    }
                  }),
                  h('span', {
                    style: {
                      cursor: 'pointer',
                      color: !this.setReBtnStatus(params.row) ? '#2d8cf0' : '#c5c8ce'
                    }
                  })
                ]
              ),
              h(
                'Poptip',
                {
                  props: {
                    confirm: true,
                    'ok-text': '确定',
                    'cancel-text': '取消',
                    type: 'error',
                    size: 'large',
                    title: '确定要删除这个课程吗?',
                    transfer: true
                  },
                  style: {
                    marginLeft: '0px'
                  },
                  on: {
                    'on-ok': () => {
                      this.delCourseInfo(params.row.ccid);
                    }
                  }
                },
                [
                  h(
                    'Button',
                    {
                      props: {
                        type: 'text',
                        size: 'small',
                        disabled: this.setReBtnStatus(params.row)
                      },
                      attrs: {
                        title: '删除'
                      },
                      style: {
                        //              marginRight: '5px',
                        background: 'none',
                        border: 'none',
                        boxShadow: 'none'
                      }
                    },
                    [
                      h('img', {
                        attrs: {
                          src: !this.setReBtnStatus(params.row)
                            ? require('../../../assets/project/delNote-h.png')
                            : require('../../../assets/project/delNote-d.png')
                        },
                        style: {
                          cursor: 'pointer',
                          'margin-right': '5px',
                          'vertical-align': 'middle',
                          //					                            width:'16px',
                          //					                            height:'16px',
                          display: 'inline-block',
                          marginBottom: '4px'
                        }
                      }),
                      h('span', {
                        style: {
                          cursor: 'pointer',
                          color: !this.setReBtnStatus(params.row) ? '#2d8cf0' : '#c5c8ce'
                        }
                      })
                    ]
                  )
                ]
              )
            ]);
          }
        }
      ],
      //课程课件
      expModal: false, //课程课件modal
      courseExpList: [], //课程课件列表
      expCol1: [
        {
          title:'序号',
          type: 'index',
          width: 60,
          align: 'center',
          ellipsis: true,
          tooltip: true
        },
        {
          title: '名称',
          key: 'ecname',
          align: 'center',
          ellipsis: true,
          tooltip: true
        },
        {
          title: '设计者',
          key: 'designer',
          align: 'center',
          ellipsis: true,
          tooltip: true
        },
        {
          title: '难度',
          key: 'difficulty',
          align: 'center',
          render: (h, params) => {
            let _this = this;
            return h('span', _this.handleDiffcult(params.row.difficulty));
          }
        },
        {
          title: '课时',
          key: 'hours',
          align: 'center',
          width: 80,
          ellipsis: true,
          tooltip: true
        },
        {
          title: '机器数',
          key: 'vmCount',
          width: 100,
          align: 'center',
          ellipsis: true,
          tooltip: true
        },
        {
          title: '创建时间',
          key: 'createTime',
          align: 'center'
          //						ellipsis: true,
          //						tooltip:true
        },
        {
          title: '描述',
          key: 'description',
          align: 'center',
          tooltip:true
        }
      ],
      courseSubscriber: [],
      subscriberModal: false,
      subscriberCol: [
        {
          title: '昵称',
          key: 'username',
          align: 'center',
          ellipsis: true,
          tooltip: true
        },
        {
          title: '使用方式',
          key: 'type',
          align: 'center',
          ellipsis: true,
          tooltip: true
        },
        {
          title: '使用时间',
          key: 'createtime',
          align: 'center'
          //						ellipsis: true,
          //						tooltip:true
        }
      ],
      setTableHei: '',
      showDefImg: true,
      showDefText: '加载中',
      //查询--更多显示
      showMore: false,
      queryHeight: 274,
      // 获取标签
      expClassifyTag: []
    };
  },
  computed: {},
  mounted() {
    this.getSelLabelType();
    this.getDirection().then((data) => {
      //赋值查询条件
      let queryObj = sessionStorage.getItem('queryObj');
      if (queryObj) {
        let params = JSON.parse(queryObj);
        this.createByMe = params.createUserID == this.USER_ID;
        this.searchCourse = params.ccname;
        this.searchSceneDesignerValue = params.designer;
        this.searchTypeCodeLevel1 = params.searchTypeCodeLevel1 || 'All';
        // this.changeTypeLevel1(this.searchTypeCodeLevel1);
        this.searchTypeCode = params.typeCode || 'All';
        this.selectDifficult = params.difficulty || 'All';
        this.isPublic = params.isPublic || 'All';
        this.curPage = Number(params.pageIndex) || 1;
        sessionStorage.removeItem('queryObj');
      }
      //				this.curPage = this.$route.query.page;
      this.getAllCourse();
    });
  },
  filters: {
    difficultyFilter(val) {
      let difficultyStr = '';
      val = val.toLowerCase();
      switch (val) {
        case 'simple':
          difficultyStr = '简单';
          break;
        case 'commonly':
          difficultyStr = '一般';
          break;
        case 'medium':
          difficultyStr = '中等';
          break;
        case 'hard':
          difficultyStr = '较难';
          break;
      }
      return difficultyStr;
    },
    filterDiff(val, type) {
      let text = '';
      let color = '';
      if (val === 1 || val === '1') {
        text = '单位';
        color = 'green';
      } else if (val === 0 || val === '0') {
        text = '个人';
        color = '#f02828';
      } else if (val === 2 || val === '2') {
        text = '系统';
        color = '#2f70ff';
      }
      if (type == 'color') {
        return color;
      } else {
        return text;
      }
    }
  },
  methods: {
    updateTableHei() {
      setTimeout(() => {
        this.queryHeight = document.querySelector('.filter-wrap').offsetHeight;
        this.setTableHei = this.fullHeight - 60 - 52 - 49 + 50 - this.queryHeight;
      }, 600);
    },
    // 获取标签
    getSelLabelType() {
      getSelLabelType()
        .then((res) => {
          if (res.code == 1) {
            // this.expClassifyTag = res.data[0].dictEntryList
            this.expClassifyTag = res.data[0].dictEntryList.map((item) => {
              return {
                key: item.dictname,
                value: item.dictname
                // value: item.dictid
              };
            });
          } else {
            this.$Message.error('获取标签失败，请刷新重试');
          }
        })
        .catch((error) => {
          this.$Message.error({
            content: error,
            duration: 3
          });
        });
    },
    //显示添加或者修改课程弹框
    showAddAndUpdate(obj, type) {
      if (type == 'add') {
        this.$router.push({
          name: 'creatCourse',
          query: {
            page: this.curPage,
            action: 'create'
          }
        });
      } else if (type == 'modify') {
        sessionStorage.setItem('queryObj', this.queryObj);
        this.$router.push({
          name: 'creatCourse',
          query: {
            page: this.curPage,
            action: 'modify',
            ccid: obj.row.ccid,
            typeCode: obj.row.typeCode
          }
        });
      }
    },
    //获取课程资源
    getAllCourse: debounce(function(val) {
      let _this = this;
      if (_this.courseListLoading) {
        //正在请求，有新的请求
        _this.hasNoExecuteRequest = true;
        return;
      }
      _this.courseListLoading = true;
      _this.showDefImg = true;
      _this.showContent = false;
      _this.showDefText = '加载中';
      let params = {
        pageIndex: _this.curPage,
        pageSize: _this.curSize,
        selfType: this.isSelf
      };
      if (_this.createByMe) {
        params.createUserID = _this.USER_ID;
      }
      if (_this.searchCourse) {
        params.ccname = _this.searchCourse;
      }
      if (_this.searchTypeCodeLevel1 && this.searchTypeCodeLevel1 != 'All') {
        params.typeCode = this.searchTypeCodeLevel1;
      }
      if (_this.searchTypeCode && this.searchTypeCode != 'All') {
        params.typeCode = this.searchTypeCode;
      }
      if (_this.selectDifficult && this.selectDifficult != 'All') {
        params.difficulty = this.selectDifficult;
      }
      if (_this.isPublic && this.isPublic != 'All') {
        params.isPublic = this.isPublic;
      }
      if (this.labelExp != 'All') {
        params.labels = this.labelExp;
      }
      //查询条件
      this.queryObj = JSON.stringify(
        Object.assign(params, {
          searchTypeCodeLevel1: this.searchTypeCodeLevel1,
          searchTypeCode: this.searchTypeCode
        })
      );
      getcourselist(params)
        .then((data) => {
          if (data.code == 1) {
            _this.courseData = data.data.items;
            if (_this.courseData.length <= 0) {
              _this.showDefImg = true;
              _this.showDefText = '暂无信息';
            } else {
              _this.showDefImg = false;
            }
            _this.courseData.forEach((course) => {
              _this.getCourseSubscriber(course);
            });
            _this.totalCount = data.data.total;
          } else {
            _this.courseData = [];
            _this.showDefImg = true;
            _this.showDefText = '暂无信息';
            _this.$Message.error(data.message);
          }
          _this.courseListLoading = false;
          if (_this.hasNoExecuteRequest) {
            _this.courseOnChange(1);
            _this.hasNoExecuteRequest = false;
          }
        })
        .catch((err) => {
          _this.courseData = [];
          _this.showDefImg = true;
          _this.showDefText = '暂无信息';
          _this.courseListLoading = false;
          if (_this.hasNoExecuteRequest) {
            _this.courseOnChange(1);
            _this.hasNoExecuteRequest = false;
          }
          _this.$Message.error('获取课程列表失败，请稍后再试');
        });
    }, 500),
    //收藏人数
    getCourseSubscriber(course) {
      let params = {
        ccid: course.ccid
      };
      getCourseSubscriber(params)
        .then((data) => {
          if (data.code == 1) {
            this.$set(
              course,
              'subscriber',
              data.attribute.dataList.map((item) => {
                return {
                  username: item.userName,
                  coursename: item.coursename,
                  type: item.resourceassignflag == 'T' ? '教学使用' : '自学收藏',
                  createtime: item.createtime
                };
              })
            );
            this.$set(
              course,
              'subscriberNum',
              data.attribute.dataList.length
              // new Set(data.attribute.dataList.map((user) => user.userId)).size
            );
          } else {
            this.$Message.error(data.message);
          }
        })
        .catch((error) => {
          console.log(error);
          //this.$Message.error(error)
        });
        // 平均得分
				getScoreAvg({experimentId: course.ccid}).then(data => {
					if(data.code == 1) {
						this.$set(course, 'scoreAvg', data.data.avg || '-')
					}
				}).catch(error => {
					console.log(error)
				})
    },
    //过滤
    searchCou() {
      this.curPage = 1;
      //				this.curSize = 10;
      this.getAllCourse();
    },
    //难度查虚查询
    changeDiff(val) {
      this.selectDifficult = val;
      this.searchCou();
    },
    //可见度查询
    changeIsPublic(val) {
      this.isPublic = val;
      this.searchCou();
    },
    changeLabelExp(val) {
      this.labelExp = val;
      this.searchCou();
    },
    //类型查询
    changeType(val) {
      this.searchTypeCode = val;
      this.searchCou();
    },
    //方向查询
    changeTypeLevel1(val) {
      this.searchTypeCode = 'All';
      if (val == 'All') {
        this.directionsLevel2 = this.directions.filter((dict) => dict.parentid);
      } else {
        this.directionsLevel2 = this.directions.filter((dict) => dict.parentid == val);
      }
      this.searchTypeCodeLevel1 = val;
      this.searchCou();
      this.$refs.directionType.updateHeight();
    },
    //删除课程
    delCourseInfo(id) {
      let _this = this;
      let params = {
        ccId: id,
        userId: this.USER_ID
      };
      delCourse(params)
        .then((data) => {
          if (data.code == 1) {
            _this.$Message.success('删除成功');
            _this.getAllCourse();
          } else {
            this.$Message.error(data.message);
          }
        })
        .catch((err) => {
          this.$Message.error(err);
        });
    },
    // 课程分页
    courseOnChange(page) {
      this.curPage = page;
      this.getAllCourse();
    },
    changeSize(size) {
      this.curSize = size;
      this.getAllCourse();
    },
    //刷新
    refreshIcon() {
      this.curPage = 1;
      this.isSelf = '';
      this.searchCourse = '';
      this.createByMe = false;
      this.searchTypeCode = 'All';
      this.searchTypeCodeLevel1 = 'All';
      this.directionsLevel2 = this.directions.filter((dict) => dict.parentid);
      this.selectDifficult = 'All';
      this.isPublic = 'All';
      this.labelExp = 'All';
      this.getAllCourse();
    },
    //获取方向
    getDirection() {
      let _this = this;
      return experType()
        .then((data) => {
          if (data.code == 1) {
            _this.directions = data.attribute.attribute[0].dictEntryList;
            _this.directions.forEach((dict) => {
              dict.key = dict.dictid;
              dict.value = dict.dictname;
            });
            _this.directionsLevel1 = _this.directions.filter((dict) => !dict.parentid);
            _this.directionsLevel2 = _this.directions.filter((dict) => dict.parentid);
          } else {
            _this.$Message.error(data.message);
          }
        })
        .catch((err) => {
          _this.$Message.error('获取方向错误，请稍后重试');
        });
    },
    // 按钮点击状态
    setReBtnStatus(params) {
      let userid = params.createUserID;
      if ((userid === this.USER_ID || this.isRootDesigner) && params.isPublic != 2) {
        return false;
      } else {
        return true;
      }
    },
    //课程课件
    showCourseExpModal(ccid) {
      this.expModal = true;
      courseExpDetail(ccid).then((data) => {
        if (data.code == 1) {
          this.courseExpList = data.data;
        }
      });
    },
    //进入课程详情
    goCourseDetail(item) {
      sessionStorage.setItem('queryObj', this.queryObj);
      this.$router.push({
        name: 'coursedetails',
        query: {
          page: this.curPage,
          ccid: item.ccid
        }
      });
    },
    //修改课程可用状态
    changeCourseEnable(courseId, enable) {
      let params = {
        courseIds: [courseId],
        enable: enable
      };
      let str = enable == 1 ? '启用' : '禁用';
      changeCourseEnable(params)
        .then((data) => {
          if (data.code == 1) {
            this.$Message.info(str + '成功');
            this.getAllCourse();
          } else {
            this.$Message.error(str + '失败');
          }
        })
        .catch((error) => {
          this.$Message.error(str + '失败');
        });
    },
    // 困难程度
    handleDiffcult(val) {
      switch (val) {
        case 'Simple':
          return '简单';
          break;
        case 'Medium':
          return '中等';
          break;
        case 'Hard':
          return '较难';
          break;
      }
    },
    //方向&类型
    handleTypeCode(dictid) {
      let dictMap = {};
      this.directions.forEach((exp) => {
        dictMap[exp.dictid] = exp.dictname;
      });
      return dictMap[dictid];
    }
  }
};
</script>

<style scoped>
.filter-wrap {
  /* padding: 0 20px;
  margin-top: 20px; */
  font-size: 14px;
  color: #8f90a6;
}
</style>
<style>
.switchSmall .ivu-switch-checked:after {
  left: 33px !important;
}
</style>
